package com.anti.modular.sys.org.dao.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.anti.jdbc.DBUtils;
import com.anti.modular.sys.org.dao.SysOrgDao;
import com.anti.modular.sys.org.entity.SysOrg;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @Description TODO
 * @Author anTi
 * @Date 2021-3-11
 */
@Repository
public class SysOrgDaoImpl implements SysOrgDao {
    @Resource
    DBUtils dbUtils;

    @Override
    public void save(SysOrg sysOrg) {
        String sql="INSERT INTO sys_org (pid, pids, name, code, sort, remark, status,create_time, create_user) VALUES (?,?,?,?,?,?,?,?,?)";
        dbUtils.execSql(sql,sysOrg.getPid(),sysOrg.getPids(),sysOrg.getName(),sysOrg.getCode(),sysOrg.getSort(),sysOrg.getRemark(),sysOrg.getStatus(),
                sysOrg.getCreateTime(),sysOrg.getCreateUser());
    }

    @Override
    public void update(SysOrg sysOrg) {
        String sql="update sys_org set pid=?, pids=?, name=?, code=?, sort=?, remark=?, update_time=?, update_user=? where id = ? ";
        dbUtils.execSql(sql,sysOrg.getPid(),sysOrg.getPids(),sysOrg.getName(),sysOrg.getCode(),sysOrg.getSort(),sysOrg.getRemark(),
                sysOrg.getUpdateTime(),sysOrg.getUpdateUser(),sysOrg.getId());
    }

    @Override
    public void delete(Long id) {
        String sql="update sys_org set status =2 where id =?";
        dbUtils.execSql(sql,id);
    }

    @Override
    public void deleteAllChild(List<Long> childIdList) {
        HashMap<Object, Object> map = CollectionUtil.newHashMap();
        String sql="update sys_org set status =2 where id in (:ids)";
        map.put("ids",childIdList);
        dbUtils.execSql(sql,map);
    }
}
